package com.java.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.java.dao.ActivitySiteDao;
import com.java.domain.ActivitySite;
import com.java.domain.event.ActivitySiteEvent;
import com.java.service.SiteService;
import com.java.util.MyTools;
import com.java.util.resp.BaseRespone;
import com.java.util.resp.TableRespone;

@Service
public class SiteServiceImpl implements SiteService {

	@Resource ActivitySiteDao siteDao;

	@Override
	public TableRespone getList(int page, int size, Integer siteDel) {
		Map<String, Object> params = new HashMap<String, Object>();
		if(!MyTools.isEmpty(siteDel)) {
			params.put("siteDel", siteDel);
		}
		List<ActivitySiteEvent> list = siteDao.selectAll(params, page, size);
		long total = siteDao.selectAllCount(params);
		return new TableRespone(list, total);
	}

	@Override
	public ActivitySiteEvent getOne(String siteId) {
		ActivitySiteEvent info = siteDao.selectByKey(siteId);
		return info;
	}

	@Override
	public BaseRespone saveSite(ActivitySite site) {
		int row = 0;
		ActivitySite info = siteDao.selectByKey(site.getSiteId());
		if(null == info) {
			info = new ActivitySite()
			.setSiteId(MyTools.getUUID())
			.setSiteDel(0)
			.setSiteTime(new Date())
			.setSiteTitle(site.getSiteTitle())
			.setSiteAddress(site.getSiteAddress());
			row = siteDao.insertSelective(info);
		}else {
			info.setSiteTitle(site.getSiteTitle())
			.setSiteAddress(site.getSiteAddress());
			row = siteDao.updateSelective(info);
		}
		return BaseRespone.result(row, "Success");
	}

	@Override
	public BaseRespone delSite(String siteId) {
		int row = siteDao.deleteUpdate(siteId, "site_del");
		return BaseRespone.result(row, "Delete Success");
	}

}
